package com.eraasoftware.npa.io;

import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Date;

import com.eraasoftware.npa.client.ActionHandler;
import com.eraasoftware.npa.client.Header;
import com.eraasoftware.npa.client.Parameter;
import com.eraasoftware.npa.client.Header.ActionEnum;
import com.esotericsoftware.kryo.Kryo;

/**
 * 
 * @author eddie
 * 
 */
public class Serializer {
	Kryo kryo = new Kryo();
	static Serializer instance = new Serializer();

	public static Serializer instance() {
		return instance;
	}

	private Serializer() {
		kryo.register(Parameter.class);
		kryo.register(Header.class);
		kryo.register(ArrayList.class);
		kryo.register(ActionEnum.class);
		kryo.register(ActionHandler.class);
		kryo.register(Date.class);

	}

	public static Serializer register(@SuppressWarnings("rawtypes") Class newClass) {
		instance().kryo.register(newClass);
		return instance();
	}

	public <T> T readObject(ByteBuffer buff, Class<T> class_) {
		return kryo.readObject(buff, class_);
	}

	public void writeObject(ByteBuffer buff, Object o) {
		kryo.writeObject(buff, o);
	}

}
